// component/completed/index.ts
import { orderList,stewarAllOrder } from '../../api/order'
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    userID:{
      type:Number,
    },
    comID:{
      type:Number,
    },
    day:{
      type:String,
    },
    teday:{
      type:String
    },
    history:{
      type:String
    }
  },
  observers:{
    'userID':function(newVal){
      const type = this.data.tabsName
      const comID = this.properties.comID;
      const userID = this.properties.userID;
      const position = wx.getStorageSync("userInfo").data.position
      if(position=='管家'){
        stewarAllOrder(comID, userID, type, '1').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          // console.log(this.data.dataList)
        })
      }else{
        orderList(comID, userID, type, '1').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          // console.log(this.data.dataList)
        })
      }

    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    tabsName: '1' as string,
    comID: -1,
    userID: -1,
    dataList: [],
    isFresh: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleTabs(e: any) {
      this.setData({
        tabsName: e.detail.name
      })
      switch (e.detail.name) {
        case '1':
          this.getInfo('1');
          break;
        case '2':
          this.getInfo('2');
          break;
        case '3':
          this.getInfo('3');
          break;
      }
    },
    getInfo(type: string) {
      const comID = this.properties.comID;
      const userID = this.properties.userID;
      const position = wx.getStorageSync("userInfo").data.position
      if(position=='管家'){
        stewarAllOrder(comID, userID, type, '1').then((res: any) => {
          console.log(res)
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
        })
      }else{
        orderList(comID, userID, type, '1').then((res: any) => {
          if (res.data.code == 200) this.setData({ dataList: res.data.data, isFresh: false })
          // console.log(this.data.dataList)
        })
      }
    },
    fresh() {
      this.setData({
        isFresh: true
      })
      this.triggerEvent('getSum')
      switch (this.data.tabsName) {
        case '1':
          this.getInfo('1');
          break;
        case '2':
          this.getInfo('2');
          break;
        case '3':
          this.getInfo('3');
          break;
      }
    }
},
  lifetimes: {
  attached: function () {
    // 在组件实例进入页面节点树时执行
    // this.setData({
    //   comID: wx.getStorageSync("userInfo").data.comID,
    //   userID: wx.getStorageSync("userInfo").data.userID
    // })
  },
  detached: function () {
    // 在组件实例被从页面节点树移除时执行
  },
  moved: function () {

  }
},
  pageLifetimes: {
  show: function () {
    // 页面被展示

    // switch (this.data.tabsName) {
    //   case '1':
    //     this.getInfo('1');
    //     break;
    //   case '2':
    //     this.getInfo('2');
    //     break;
    //   case '3':
    //     this.getInfo('3');
    //     break;
    // }

  },
  hide: function () {
    // 页面被隐藏
  },
  resize: function () {
    // 页面尺寸变化
  }
}
})